/**
 * 
 */
package denaris.core.entity;

import javax.microedition.lcdui.game.Sprite;

import denaris.core.AbstractDenarisMap;
import denaris.core.controller.AbstractController;
import denaris.core.controller.StaticController;
import denaris.core.controller.VectorExplosionController;

/**
 * Represents an evil entity :-)
 * 
 * @author stkl23
 * 
 */
public class Enemy extends AbstractEntity {
	public Enemy(AbstractDenarisMap parentMap, int score) {
		super(parentMap, score);
	}

	public AbstractController createController() {
		return new StaticController();
	}

	public void onScopeLeft() {
		getParentMap().removeEnemy(this);
	}

	/**
	 * this method is called when an enemy is shot.. not when it's nuked. The
	 * difference is the Controller that is assigned to the explosion.
	 */
	public Explosion explode() {
		Explosion explosion = super.explode(0, 0);
		AbstractController ctrl = explosion.getController();
		ctrl.deactivate();
		// we must now change the controller
		Sprite sprite = ctrl.getSprite();
		explosion.setController(new VectorExplosionController(sprite.getX(),
				sprite.getY(), 2, 0));
		explosion.setTurnToCollectible(explosion.shouldCreateCollectible());

		AbstractDenarisMap map = getParentMap();
		map.removeEnemy(this);
		map.addFriend(explosion);

		return explosion;
	}

	public Explosion explode(int childExplosions, int frameDelay) {
		// let the base class create the explosion
		Explosion explosion = super.explode(childExplosions, frameDelay);
		// we will remove ourselves from the enemy-list and put the explosion
		// into the friends list
		AbstractDenarisMap map = getParentMap();
		map.removeEnemy(this);
		map.addFriend(explosion);

		return explosion;
	}
}
